$(function () {
    $("span.ljtip").ljDetail($("#xsd_detail_ljtip").val(), {
        position: 'top'
    });

    $("#xsd_xsdmx_table").datagrid({
        url: $.webPath() + '/xsgl/xsdgl/xsdgl_xsmx?xsdId=' + $("#xsd_id").val(),
        width: 1700,
        fitColumns: false,
        singleSelect: true,
        fit: true,
        showFooter: true,
        rownumbers: true,
        columns: [
            [
                // {field:'wzgg.oldcode', title:'老物资编码', align:'center', width:150},
                {field: 'xsxt_xsdh', title: '合同子项号', width: 150, align: 'center'},
                /* {field: 'wzgg.code', title: '物资编码', width: 150, align: 'center'},*/
                {field: 'wzgg.name', title: '物资名称', width: 100, align: 'center'},
                {field: 'wzgg.cz', title: '材质', width: 50, align: 'center'},
                {field: 'wzgg.ggxh', title: '规格型号', width: 100, align: 'center'},
                {field: 'carNo', title: '车皮号', width: 85},
                {field: 'bindNo', title: '捆包号', align: 'center', width: 100},
                {field: 'wzgg.th', title: '图号', hidden: true, align: 'center'},
                {field: 'ck', title: '长宽', hidden: true, align: 'right'},
                {field: 'wzgg.dw', title: '单位', width: 50, align: 'center'},
                {field: 'jzfs.z', title: '记重方式', width: 50, align: 'center'},
                {field: 'kh.khbm', title: '卡号', width: 120, align: 'center'},
                {field: 'js', title: '件数', width: 50, align: 'right'},
                {field: 'sbsl', title: '重量', width: 100, align: 'right',
                    formatter: function (value) {
                        var sl = formatSlForHtml(value, ",");
                        return sl;
                    }},
                {field: 'hsj', title: '含税单价(元)', width: 150, align: 'right',
                    formatter: function (value) {
                        var sl = formatJeForHtml(value);
                        return sl;
                    } },
                {field: 'sjdj', title: '实际单价', width: 150, align: 'right',
                    formatter: function (value) {
                        var sl = formatJeForHtml(value);
                        return sl;
                    } },
                {field: 'hse', title: '含税总金额(元)', width: 150, align: 'right',
                    formatter: function (value) {
                        var sl = formatJeForHtml2(value);
                        return sl;
                    } },
                {field: 'bhsj', title: '不含税单价(元)', width: 150, align: 'right',
                    formatter: function (value) {
                        var sl = formatJeForHtml(value);
                        return sl;
                    } },
                {field: 'ghje', title: '购货总金额(元)', width: 150, align: 'right',
                    formatter: function (value) {
                        var sl = formatJeForHtml(value);
                        return sl;
                    } },
                {field: 'cgd.cgdh', title: '采购单号', align: 'center', formatter: function (value, row) {
                    if (row['cgd.id']) {
                        return "<a style='color:red' href='javascript:void(0);' onclick='viewXsdglCgdDetail(" + row['cgd.id'] + ")'>" + value + "</a>";
                    } else
                        return value;
                }, width: 100},
                {field: 'jsdh', title: '结算单号', align: 'center', width: 100, formatter: xsdToXsjsdCell}

            ]
        ],
        loadFilter: function (data) {
            $.each(data.rows, function () {
                if (this.hsj) {
                    this.hse = Math.round(multiply(this.sbsl, this.hsj) * 100) / 100;
                }
                if (this.bhsj) {
                    this.bhse = Math.round((this.hse / (1 + $("#xsd_detail_sl").val() / 100)) * 100) / 100;
                }
            })
            return data;
        },
        onLoadSuccess: function () {
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');

        }
    })
})

function viewXsdglXshtDetail(id) {
    $.window({
        iconCls: 'icon-tip',
        title: "详细信息",
        url: $.webPath() + "/htgl/xshtgl/xshtgl_detail?xshtId=" + id,
        width: 1050,
        height: 500,
        modal: true,
        isMax: false
    })
}

